<template>
  <div class="home-new">
    <home-panel :title="title" :sub-title="subTitle">
      <template #right><XtxMore path="/"/></template>
      <!-- 面板内容 -->
      <div ref="target" style="position: relative;height: 406px;">
        <ul v-if="goods.length" class="goods-list">
          <!-- 数据没加载过来展示骨架 -->

          <li v-for="item in goods" :key="item.id">
            <RouterLink :to="`/product/${item.id}`">
              <img :src="item.picture" alt="" />
              <p class="name ellipsis">
                {{ item.name }}
              </p>
              <p class="price">
                {{ "&yen;" + item.price }}
              </p>
            </RouterLink>
          </li>
          <!-- 每个图片 -->
        </ul>
        <!-- 数据没加载过来展示骨架 -->
        <home-skeleton v-else bg="#fff"></home-skeleton>
      </div>
    </home-panel>
  </div>
</template>
<script>
import { ref } from "vue";

import homePanel from "@/components/home/homePanel.vue";
import homeSkeleton from "@/components/home/homeSkeleton.vue";
import { homeNewObj } from "@/api";
import { useLazyData } from "@/hooks";

export default {
  props: {
    title: String,
    subTitle: String,
    falg: Boolean,
  },
  name: "HomeNew",
  setup(p, { emit }) {
    // let goods = ref([]); // 新鲜好物
    // 获取监听可视区
    // const target = ref(null);
    // // 懒加载
    // console.log(target);
    // let result = useLazyData(target, homeNewObj);
    const { target, result } = useLazyData(homeNewObj);
    return {
      goods: result,
      target,
    };
  },
  components: { homePanel, homeSkeleton },
};
</script>
<style scoped lang="scss">
.fade {
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity 0.5s 0.2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    &:hover {
      @include hoverShadow;
    }
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: $priceColor;
    }
    .ccc {
      color: #999999;
      font-size: 18px;
    }
  }
}
</style>
